<?php
/**
 * Theme a wordgame page.
 */
function template_preprocess_wordgame_page(&$variables) {
  // Helpful $content variable for templates.
  $variables += array('page' => array());
  foreach (element_children($variables['elements']) as $key) {
    $variables['page'][$key] = $variables['elements'][$key];
  }

  // Gather nodejschat classes.
  $variables['classes_array'][] = drupal_html_class('wordgame-page');

  // Add additional libraries, CSS, JavaScript an other custom
  // attached data associated with this element.
  if (!empty($variables['elements']['#attached'])) {
    drupal_process_attached($variables['elements']);
  }
}
/**
 * Theme a wordgame board.
 */
function template_preprocess_wordgame(&$variables) {
  $wordgame = $variables['elements']['#wordgame'];

  // Flatten the node object's member fields.
  $variables = array_merge((array) $wordgame, $variables);

  // Helpful $content variable for templates.
  $variables += array('content' => array());
  foreach (element_children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }

  // Gather nodejschat classes.
  $variables['classes_array'][] = drupal_html_class('wordgame-container');

  // Add additional libraries, CSS, JavaScript an other custom
  // attached data associated with this element.
  if (!empty($variables['elements']['#attached'])) {
    drupal_process_attached($variables['elements']);
  }
}

/**
 *
 */
function theme_wordgame_letter($vars) {
  $attributes = array('class' => array('letter-cell'));
  if ($vars['type']) {
    $attributes['class'][] = 'letter-' . $vars['type'];
  }
  if ($vars['word_index']) {
    $attributes['class'][] = implode(" ", $vars['word_index']);
  }
  $attributes['class'][] = 'row-' . $vars['row'];
  $attributes['class'][] = 'col-' . $vars['col'];
  $output = "<div id=\"cell-{$vars['row']}-{$vars['col']}\" " . drupal_attributes($attributes) . '>' . $vars['letter'] . '</div>';
  return $output;
}